--------------------------------------------------------- 
-- BandageApplying
--------------------------------------------------------- 
BandageApplying()     
   print("Applying Bandage ... ")  
   stateHandler.Bandage.State=true
   stateHandler.Bandage.Time=getticks() 
end
 
--------------------------------------------------------- 
-- BandageApplied
--------------------------------------------------------- 
function BandageApplied()     
   print("Bandage applied ! (" .. getticks()-stateHandler.Bandage.Time .. "ms)")  
   stateHandler.Bandage.State=false
end
 
--------------------------------------------------------- 
-- State Handlers
--------------------------------------------------------- 
stateHandler={ 
  --------------------------------------------------------- 
  -- Bandage states
  ---------------------------------------------------------     
  ["Bandage"]={ 
        ["State"]=false, 
        ["LastJRef"]=UO.ScanJournal(0), 
        ["Time"]=getticks(),            
        ["Filter"]={     
            { "You apply the bandages, but they barely help.", 
              BandageApplied }, 
               
            { "You finish applying the bandages.", 
              BandageApplied }, 
               
            { "You heal what little damage your patient had.", 
              BandageApplied }, 
             
            { "You begin applying the bandages.", 
              BandageApplying }, 
         
            { "That being is not damaged!", 
              BandageApplied }            
        } 
    },     
} 
             
--------------------------------------------------------- 
-- CheckJournal
--------------------------------------------------------- 
function CheckJournal()     
    for k,v in pairs(stateHandler) do
        v["LastJRef"], nCnt = UO.ScanJournal(v["LastJRef"]) 
        ScanJournalFor(v, nCnt) 
    end
end
      
        
--------------------------------------------------------- 
-- ScanJournalFor
---------------------------------------------------------         
function ScanJournalFor(x, nCnt) 
    for ji=0,nCnt-1 do
        for k,v in pairs(x["Filter"]) do
            if string.find(UO.GetJournal(ji),"^"..v[1]) then v[2]() end
        end
    end
    return false
end
 
 
--------------------------------------------------------- 
-- checkHeal
--------------------------------------------------------- 
function checkHeal() 
   if (UO.Hits<UO.MaxHits) and (stateHandler.Bandage.State==false) then
        _wait(500)          
        UO.Macro(58,0)         
        _wait(500) 
   end
end
 
 
--------------------------------------------------------- 
-- WaitHook
--------------------------------------------------------- 
function WaitHook(ms) 
    e=getticks()+ms
    while e>=getticks() do
        CheckJournal() 
        checkHeal()         
        _wait(1) 
  end
end
 
 
--------------------------------------------------------- 
-- installhook
--------------------------------------------------------- 
function installhook()  
   _wait = wait  
   wait = WaitHook
end
installhook()
